//
//  TMMyDiscountCell.m
//  国学商家管理
//
//  Created by Tao Li on 2018/7/6.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMMyDiscountCell.h"
#import "TMDiscountModel.h"
@implementation TMMyDiscountCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.useImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(useDiscount:)];
    [self.useImageView addGestureRecognizer:tap];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setIsmine:(BOOL)ismine{
    _ismine = ismine;
    if (ismine == YES) {
        self.useLabel.text = @"立即使用";
    }else{
        self.useLabel.text = @"立即领取";
    }
}
-(void)setDiscountType:(WhereDiscount)discountType{
    _discountType = discountType;
    if (discountType == WhereDiscountUse) {
        self.useLabel.text = @"立即领取";
    }else{
         self.useLabel.text = @"立即使用";
    }
}
- (void)setModel:(TMDiscountModel *)model{
    _model = model;
    self.courseTitle.text = model.title;
    self.dateLabel.text = [NSString stringWithFormat:@"有效期:%@至%@", [SPToolSet stringFromDateString:model.start], [SPToolSet stringFromDateString:model.end]];
    self.moneyLabel.text = [NSString stringWithFormat:@"¥%.02f元", model.money];
    self.canUseLabel.text = [NSString stringWithFormat:@"满%.02f元可使用",model.min_money];
}
- (void)useDiscount:(UITapGestureRecognizer *)tap{
    if (self.discountType == WhereDiscountUse) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GETDISCOUNTNOTI" object:nil userInfo:@{@"usid":@(self.model.usid),@"price":@(self.model.money)}];
        NSLog(@"1111112234");
    }if (self.discountType == WhereDiscountGet) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"USEDISCOUNTNOTI" object:nil userInfo:@{@"usid":@(self.model.usid),@"price":@(self.model.money)}];
        NSLog(@"222222112234");
    }
    if (self.discountType == WhereDiscountList) {
        if (self.model.type == 1) {
            if (self.block) {
                self.block(self.model.type,self.model.sid);
            }
        }
        if (self.model.type == 2) {
            if (self.block) {
                self.block(self.model.type,self.model.cid);
            }
        }
    }
    
}
@end
